package com.zw.cloud.mybatis.plus.service.impl.stenter;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zw.cloud.mybatis.plus.entity.stenter.BaseTenterCraftHistory;
import com.zw.cloud.mybatis.plus.enums.DeleteEnum;
import com.zw.cloud.mybatis.plus.mapper.stenter.BaseTenterCraftHistoryMapper;
import com.zw.cloud.mybatis.plus.service.api.stenter.IBaseTenterCraftHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 定型机历史工艺 服务实现类
 * </p>
 *
 * @author zw
 * @since 2023-11-14
 */
@Service
public class BaseTenterCraftHistoryServiceImpl extends ServiceImpl<BaseTenterCraftHistoryMapper, BaseTenterCraftHistory> implements IBaseTenterCraftHistoryService {

    /**
     * 定型工艺历史版本查询
     */
    @Override
    public List<BaseTenterCraftHistory> queryBaseTenterCraftHistoryByVersionId(Long versionId) {
        LambdaQueryWrapper<BaseTenterCraftHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseTenterCraftHistory::getCraftVersionId,versionId)
                .eq(BaseTenterCraftHistory::getIsDeleted, DeleteEnum.NO.getStatus());
        List<BaseTenterCraftHistory> baseTenterCraftHistories = baseMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(baseTenterCraftHistories)) {
            return Collections.emptyList();
        }
        baseTenterCraftHistories.forEach(baseTenterCraftHistory -> baseTenterCraftHistory.setCraftVersionStr(baseTenterCraftHistory.fillCraftVersionStr()));
        return baseTenterCraftHistories;
    }
}
